package com.briup.web;

import com.briup.pojo.Address;
import com.briup.pojo.Customer;
import com.briup.service.IAddressService;
import com.briup.serviceImp.AddressserviceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class SaveAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Customer login = (Customer) request.getSession().getAttribute("login");
        if (login == null){
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String telephone = request.getParameter("telephone");
        Integer customerId = Integer.parseInt(request.getParameter("customerId"));
        Address address1 = new Address(name, address, telephone, customerId);
        IAddressService addressserviceImp = new AddressserviceImp();
        addressserviceImp.saveAddress(address1);
        response.sendRedirect("./findAddressServlet");


    }
}
